﻿namespace Mp3Observer.Common.IoC
{
    using System.Configuration;

    /// <summary>
    /// ConfigurationElementCollection of Components; defines the unique key (name)
    /// </summary>
    [ConfigurationCollection(typeof(ComponentElement))]
    public class ComponentsCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// Gets or sets the resolver.
        /// </summary>
        /// <value>The resolver.</value>
        [ConfigurationProperty("resolver", DefaultValue = "", IsRequired = true)]
        public string Resolver
        {
            get { return (string)base["resolver"]; }
            set { base["resolver"] = value; }
        }

        /// <summary>
        /// Gets the <see cref="ComponentElement"/> with the specified idx.
        /// </summary>
        /// <param name="idx">collection index</param>
        /// <value></value>
        public ComponentElement this[int idx]
        {
            get { return (ComponentElement)BaseGet(idx); }
        }

        /// <summary>
        /// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </summary>
        /// <returns>
        /// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new ComponentElement();
        }

        /// <summary>
        /// Gets the element key for a specified configuration element when overridden in a derived class.
        /// </summary>
        /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
        /// <returns>
        /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ComponentElement)element).Name;
        }
    }
}
